<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include  file="/jsps/front/common/taglibs.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>

		<title>${good.goodsName} 商品信息</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		
		<link rel="stylesheet" type="text/css" href="<c:url value="/jsps/front/css/comm_answer.css"/>">
		<link rel="stylesheet" type="text/css" href="<c:url value="/jsps/front/css/good_show.css"/>">
		<link rel="stylesheet" type="text/css" href="<c:url value="/jsps/front/css/head.css"/>">
		 <link rel="stylesheet" type="text/css" href="<c:url value="/jsps/front/css/application.css"/>">
		

		<script type="text/javascript">
		
	 	function buy(goodCnt,goodNo){
	 		var goodNum=document.getElementById('goodNum').value;
           if(goodNum>goodCnt)
             alert("你所要购买的商品数量大于库存量，请重新输入!");
           else if(confirm("你确认要购买"+goodNum+"件"+"该商品吗?")){
             location.href='<c:url value="/goodMgr?act=addGoodToCart"/>&goodNo='+goodNo+'&goodNum='+goodNum;
             }  
	 	}
	 	
	 	
function getEventObject(W3CEvent) {//事件标准化函数
	return W3CEvent || window.event;
}
function getPointerPosition(e) {//兼容浏览器的鼠标x,y获得函数
	e = e || getEventObject(e);
	var x = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
	var y = e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
	
	return { 'x':x-400,'y':y-200 };
}
function setOpacity(elem,level) {//兼容浏览器设置透明值
	if(elem.filters) {
		elem.style.filter = 'alpha(opacity=' + level * 100 + ')';
	} else {
		elem.style.opacity = level;
	}
}
function css(elem,prop) {	//css设置函数,可以方便设置css值,并且兼容设置透明值
	for(var i in prop) {
		if(i == 'opacity') {
			setOpacity(elem,prop[i]);
		} else {
			elem.style[i] = prop[i];
		}
	}
	return elem;
}
var magnifier = {
	m : null,
	
	init:function(magni){
		var m = this.m = magni || {
			cont : null,	//装载原始图像的div
			img : null,	//放大的图像
			mag : null,	//放大框
			scale : 15	//比例值,设置的值越大放大越大,但是这里有个问题就是如果不可以整除时,会产生些很小的白边,目前不知道如何解决
		}
		
		css(m.img,{	
			'position' : 'absolute',
			'width' : (m.cont.clientWidth * m.scale) + 'px',				//原始图像的宽*比例值	
			'height' : (m.cont.clientHeight * m.scale) + 'px'				//原始图像的高*比例值
			})
		
		css(m.mag,{
			'display' : 'none',
			'width' : m.cont.clientWidth + 'px',	//m.cont为原始图像,与原始图像等宽
			'height' : m.cont.clientHeight + 'px',
			'position' : 'absolute',
			'left' : m.cont.offsetLeft + m.cont.offsetWidth + 390 + 'px',//放大框的位置为原始图像的右方远10px
			'top' : m.cont.offsetTop + 190 + 'px'
			})
		
		var borderWid = m.cont.getElementsByTagName('div')[0].offsetWidth - m.cont.getElementsByTagName('div')[0].clientWidth;		//获取border的宽
	
		css(m.cont.getElementsByTagName('div')[0],{			//m.cont.getElementsByTagName('div')[0]为浏览框
			'display' : 'none',								//开始设置为不可见
			'width' : m.cont.clientWidth / m.scale - borderWid + 'px',			//原始图片的宽/比例值 - border的宽度
			'height' : m.cont.clientHeight / m.scale - borderWid + 'px',//原始图片的高/比例值 - border的宽度
			'opacity' : 0.5//设置透明度
			})
		
		m.img.src = m.cont.getElementsByTagName('img')[0].src;//让原始图像的src值给予放大图像
		m.cont.style.cursor = 'crosshair';
		
		m.cont.onmouseover = magnifier.start;
		
	},
	
	start:function(e){
		
		if(document.all){//只在IE下执行,主要避免IE6的select无法覆盖
			magnifier.createIframe(magnifier.m.img);
		}
		
		this.onmousemove = magnifier.move;//this指向m.cont
		this.onmouseout = magnifier.end;
	},
	
	move:function(e){
		var pos = getPointerPosition(e);		//事件标准化
		
		this.getElementsByTagName('div')[0].style.display = '';
		
		css(this.getElementsByTagName('div')[0],{
			'top' : Math.min(Math.max(pos.y - this.offsetTop - parseInt(this.getElementsByTagName('div')[0].style.height) / 2,0),this.clientHeight - this.getElementsByTagName('div')[0].offsetHeight) + 'px',
			'left' : Math.min(Math.max(pos.x - this.offsetLeft - parseInt(this.getElementsByTagName('div')[0].style.width) / 2,0),this.clientWidth - this.getElementsByTagName('div')[0].offsetWidth) + 'px'			//left=鼠标x - this.offsetLeft - 浏览框宽/2,Math.max和Math.min让浏览框不会超出图像
			})
		
		magnifier.m.mag.style.display = '';
		
		css(magnifier.m.img,{
			'top' : - (parseInt(this.getElementsByTagName('div')[0].style.top) * magnifier.m.scale) + 'px',
			'left' : - (parseInt(this.getElementsByTagName('div')[0].style.left) * magnifier.m.scale) + 'px'
			})
		
	},
	
	end:function(e){
		this.getElementsByTagName('div')[0].style.display = 'none';
		magnifier.removeIframe(magnifier.m.img);		//销毁iframe
		
		magnifier.m.mag.style.display = 'none';
	},
	
	createIframe:function(elem){
		var layer = document.createElement('iframe');
		layer.tabIndex = '-1';
		layer.src = 'javascript:false;';
		elem.parentNode.appendChild(layer);
		
		layer.style.width = elem.offsetWidth + 'px';
		layer.style.height = elem.offsetHeight + 'px';
	},
	
	removeIframe:function(elem){
		var layers = elem.parentNode.getElementsByTagName('iframe');
		while(layers.length >0){
			layers[0].parentNode.removeChild(layers[0]);
		}
	}
}
window.onload = function(){
	magnifier.init({
				   cont : document.getElementById('good_pic'),
				   img : document.getElementById('magnifierImg'),
				   mag : document.getElementById('mag'),
				   scale : 3
				   });
}
   </script>

	</head>

	<body style="background-color: #769b72;">
	         
	<c:import url="/jsps/front/head.jsp"/>
	
	    <div id="allcontent">
			<div id=main>
				<DIV class=mainsearch></DIV>
				<DIV class=wrap>
					<DIV class=left>
						<DIV class=left_div_yellow1>
							<H2 class=left_title>
								浏览本商品的顾客还看过
							</H2>
							<c:forEach var="book" items="${mostvisitedbooks}">
								<H3>
									<SPAN class=point>·</SPAN><A class=blue12a
										title="${book.bookName}"
										href="<c:url value='/#'/>"
										target=_blank></A>
								</H3>
								<DIV class=dashed></DIV>
							</c:forEach>

						</DIV>
						<DIV class=left_div_gray>
							<H2 class=left_title>
								您最近的浏览历史
							</H2>
							<c:forEach var="good" items="${thisvisitedgoods}">
								<H3>
									<SPAN class=point>·</SPAN><A class=blue12a
										title=""
										href="<c:url value='/#'/>"
										target=_blank></A>
								</H3>
								<DIV class=dashed></DIV>
							</c:forEach>

						</DIV>
					</DIV>
			<c:if test="${not empty good}">	
					<DIV class=right>
						<DIV class=right_wai>
							<DIV class=shuming>
								<DIV class=shuming_left>
									<SPAN>
									  <B>商品细节展示</B>
									 </SPAN>
								</DIV>
							</DIV>
							<DIV class=good_left>
								<DIV class=good_pic id="good_pic">
									 <img id="img" style="width: 342px; height: 420px; align:center;" title="商品图片" 
							              src="<c:url value="/goodMgr?act=showGoodCover"/>&goodNo=${good.goodsNo}" border=0>
							         <div id="Browser"></div>
								</DIV>
								<div id="mag"><img id="magnifierImg" /></div>
							</DIV>
							 
							<DIV class="good_right">
							   <div>
							       <button style="float:right;" onclick="history.go(-1)">返回</button>
							   </div>
							   <br/>
							   <DIV >
									<a>商品名称: </a>${good.goodsName}
								</DIV>
								<br/>
								<DIV>
									<a>商品编号: </a>${good.goodsNo}
								</DIV>
								<br/>
								<DIV>
									<a>是否缺货：</a>
									<c:if test="${good.cnt<=10}">商品热销中 ...</c:if>
									<c:if test="${good.cnt>10}">库存充足...</c:if>
								</DIV>
								<br/>
								<DIV>
									<a>商品单价: </a>${good.goodsPrice}元
								</DIV>
								<br/>
								<div>
						          <a>商品数量:</a>	
						           <input type="text" class="text" name="cnt" 
						                  id="goodNum" size=5 value="1"/> 
				        		</div>	
				        		<br/>
				        		<br/>
								<div>
								   <a>摘要信息：</a>
									<br />
									&nbsp;${good.goodsMemo}
							    </div>
							    <br/>	
							    <DIV class="buy">
									<A title=购买 target="_blank"
										
										name=purchase_bk> 
									<IMG onclick="buy(${good.cnt },${good.goodsNo });"
									      src="<c:url value='/jsps/front/images/login/booksale.gif'/>" border=0> </A>
								</DIV>
						   </DIV>

						<DIV class=comm_answer>

							<DIV id=total_comm>
								<DIV class=total_body>
									<DIV class=people_average>
										
			                           暂时没有任何评论！
			                   
									</DIV>
									<DIV class=write_comm>
										<span id=reviewTipa onclick="gotopubcomment();"> <IMG
												title=写评论 src="<c:url value="/jsps/front/images/login/button_write_comm.gif"/>"
												border=0> </span>
									</DIV>
								</DIV>
								<DIV class=empty_clear_left></DIV>
							</DIV>
						</DIV>
					</DIV>
				</DIV>
               </c:if>
               <c:if test="${empty good}">
                   <div>没有找到相关的商品</div>
               </c:if>
			</div>
		</div>
		</div>
	</body>
</html>
